package cn.yousuowei.huanglele.scanmine;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by ihuanglele on 2017/4/15.
 */

public class Coord {

    private int row;
    private int col;
    private int current_row = -1;
    private int current_col = -1;
    private int position = 0;

    public Coord(int row,int col,int p) {
        this.row = row;
        this.col = col;
        this.position = p;
    }

    public Coord(){

    }

    public int RcToPosition(int r,int c){
        return r * this.col + c;
    }

    /**
     * 索引位置 转 坐标位置
     * @param p
     * @return
     */
    private Map<String,Integer> positionToRC(int p){
        this.position = p;
        int r = (int) Math.floor(p / this.col);
        int c = p % this.col;
        this.current_col = c;
        this.current_row = r;
        Map<String,Integer> map = new HashMap<String,Integer>();
        map.put("row",r);
        map.put("col",c);
        return  map;
    }

    public void setCol(int col) {
        this.col = col;
    }

    public void setRow(int row) {
        this.row = row;
    }

    public void setPosition(int position) {
        this.position = position;
    }

    public int getCurrent_col() {
        if(this.current_row == -1){
            positionToRC(this.position);
        }
        return current_col;
    }

    public int getCurrent_row() {
        if(this.current_row == -1){
            positionToRC(this.position);
        }
        return current_row;
    }
}
